//
//  MKHomeTableViewController.swift
//  101weibo
//
//  Created by 舒磊明 on 2019/1/17.
//  Copyright © 2019年 劢克科技. All rights reserved.
//

import UIKit

class MKHomeTableViewController: MKBaseTableViewController {
    
    private lazy var titleBtn: MKTitleButton = MKTitleButton()
    private lazy var popDelegate = MKHomePopAnimation()

    override func viewDidLoad() {
        super.viewDidLoad()

        visitorView.addRotationAnim()
        
        //Judge if is login.
        if !isLogin {
            return
        }
        
        //If login:
        setNavigationBarItem()
    }
}

//MARK: - UI
extension MKHomeTableViewController {
    private func setNavigationBarItem() {
        
        // left and right bar button item.
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_friendattention")
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: "navigationbar_pop")

        // navigation bar's title
        titleBtn.setTitle("codewhy", for: .normal)
        titleBtn.addTarget(self, action: #selector(titleBtnClick), for: .touchUpInside)
        navigationItem.titleView = titleBtn
    }
}


//MARK: - Event
extension MKHomeTableViewController: MKHomePopAnimationDelegate {
    @objc private func titleBtnClick() {
        // Pop controller
        let popVc = MKPopViewController()
        
        // Save MKHomeTableViewController.
        popVc.modalPresentationStyle = .custom
        
        // Set Delegate(change pop size; change animation.)
        popDelegate.currentFrame = CGRect(x: 100, y: 55, width: 180, height: 350)
        popVc.transitioningDelegate = popDelegate
        popDelegate.delegate = self
        
        // Pop Controller
        present(popVc, animated: true) {
            print("ok")
        }
    }
    
    func changeStatus(present: Bool) {
        titleBtn.isSelected = present
    }
}
